use actix_web::{HttpResponse, web};
use common::error::MyError;
use common::r::JsonResult;
use model::game_email::{LetterPage, SendMail};
use service::game_email::GameEmailService;

pub struct GameEmailController {}

impl GameEmailController{


    pub async fn send_mail(form: web::Json<SendMail>)-> Result<HttpResponse, MyError> {
        let res = GameEmailService::send_mail(form.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }

    pub async fn mail_page(form: web::Json<LetterPage>)-> Result<HttpResponse, MyError> {
        let res = GameEmailService::mail_page(form.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }

    pub async fn remove_letter(form: web::Path<i32>)-> Result<HttpResponse, MyError> {
        let res = GameEmailService::remove_letter(form.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }

    pub async fn remove_postal(form: web::Path<i32>)-> Result<HttpResponse, MyError> {
        let res = GameEmailService::remove_postal(form.into_inner()).await?;
        Ok(HttpResponse::Ok().json(JsonResult::ok(res)))
    }
}